using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using SouthernLand.Common;
using SouthernLand.Common.BOL.NhaDat;
using SouthernLand.Common.Untilities;

namespace SouthernLand.Controls
{
    public partial class DanhMucBDS : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Categories> obj = Categories.GetCategoriesByParentID((int)eCategory.LoaiBDS);
            if (obj != null && obj.Count > 0)
            {
                rptCategories.DataSource = obj;
                rptCategories.DataBind();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            rptCategories.ItemDataBound += rptCategories_ItemDataBound;
        }

        private void rptCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Categories categories = (Categories)e.Item.DataItem;
                if (categories != null)
                {
                    Image imgIco = (Image)e.Item.FindControl("imgIco");
                    imgIco.ImageUrl = Globals.ApplicationPath + "UserUpload/Categories/" + categories.ImageUrl;
                    HyperLink hplRealEstate = (HyperLink)e.Item.FindControl("hplRealEstate");
                    hplRealEstate.Text = categories.Title;
                    hplRealEstate.NavigateUrl = Globals.BuildUrlByRealEstate(categories.CateID, Globals.ProcessString(Globals.UnicodeToKoDau(categories.Title)));
                    Label lblMenu = (Label)e.Item.FindControl("lblMenu");
                    lblMenu.Text = Raovat.GetRaovatCountByCateID(ConvertUtility.ToInt32(categories.CateID)).ToString();
                }
            }
        }
    }
}